﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Models;
using Service;
namespace community
{
    public partial class check : Form
    {
        SqlConnection cn = new SqlConnection(SQL.conStr);
        SqlCommand comm1, comm2;
        SqlDataReader dr1, dr2;
        SqlDataAdapter cm1;
        DataSet ds;
        string tree;
        string tree1;
        string a;
        string b;
        static string strSQL = "Select INHABITANTCODE_CHR AS 居民编号,RESIDENTNAME_CHR AS 居民姓名,COMMUNITYNAME_CHR AS 所属社区,COMMUNITYCODE_CHR AS 社区编号,FAMILYNAME_CHR AS 所属家庭,FAMILYCODE_CHR AS 家庭编号,PATIENTCARDID_CHR AS 诊疗卡号,SEX_CHR AS 性别,BIRTH_DAT AS 出生日期,COUNTRY_CHR AS 国籍,NATION_CHR AS 民族,PROVINCE_CHR AS 籍贯,IDENTITYCARD_CHR AS 身份证号,RESIDENTCARD_VCHR AS 居住证号,PHONE_CHR AS 本人电话,HOMEPHONE_VCHR AS 家庭电话,CONTACTPEOPLE_CHR AS 联系人姓名,CONTACTSTYLE_CHR AS 联系人电话,FATHERNAME_VCHR AS 父亲姓名,FATHERCODE_VCHR AS 父亲编号,MOTHERNAME_VCHR AS 母亲姓名,MOTHERCODE_VCHR AS 母亲编号,MARRIAGESTATE_CHR AS 婚姻状况,CAREERSTYLE_CHR AS 职业,COMPANY_CHR AS 工作单位,RESIDENTTYPE_VCHR AS 常住类型,CULTURE_VCHR AS 文化程度,REGISTADDRESS_VCHR AS 户口地址,ADDRESSPROVINCE_VCHR AS 家庭地址省,ADDRESSCITY_VCHR AS 家庭地址市,ADDRESSCOUNTY_VCHR AS 家庭地址县,ADDRESSVILLAGE_VCHR AS 家庭地址乡,ADDRESSHAMLET_VCHR AS 家庭地址村,ADDRESSDOORPLATE_VCHR AS 家庭地址号,POSTNUM_CHR AS 邮政编码,PAYTYPE_VCHR AS 医费支付方式,E_MAIL AS 邮箱地址,QQ AS QQ号码,MSN AS MSN号,CREATEDOCTOR_CHR AS 建档医生,CREATEDOCTORID_CHR AS 建档医生ID,CREATEUNIT_VCHR AS 建档单位,CREATEDATE_DAT AS 建档时间,RECORDER_CHR AS 录入者,RECORDERID_CHR AS 录入者ID,FAMILYCORD_CHR AS 家庭编号,FIXPHONE_VCHR AS 固定电话,HOMEADDRESS_VCHR AS 家庭地址,MEMBERCOUNT_INT AS 家庭人数,ENTIRONMENT_INT AS 居住环境,FAMILYTYPE_INT AS 家庭类型,FAMILYHOUSE_INT AS 家庭住房,HOUSEAREA_INT AS 住房面积,DRINKING_INT AS 饮水类型,EARNING_INT AS 家庭月收入,ELDING_INT AS 使用燃料,DISTANCE_INT AS 离最基层医疗机构距离,MOVEOUT_INT AS 是否迁出,MOVEOUTDATE_DAT AS 迁出日期,HOUSEHOLDERNAME_VCHR AS 户主名,CREATEORGAN_VCHR AS 建档机构,MEMBERCOUNT2_INT AS 家庭人口,ALLERGICREMEDY_VCHR AS 过敏药物,ALLERGICDATE_DAT AS 过敏时间,diseasename_vchr AS 疾病名称,happendate_dat AS 患病时间,diseasetype_int AS 疾病类型,diseaseIcd_vchr AS 疾病ICD码,healdate_dat AS 治愈时间,healeffect_vchr AS 治愈效果,diagnosehospital_vchr AS 确诊医院 from sqlview where 1=1 "; 
        static string strSQL1 = "select count(SEQID_INT) from sqlview where SEX_CHR='女' ";
        static string strSQL2 = "select count(SEQID_INT) from sqlview where SEX_CHR='男' ";
        public check()
        {
            InitializeComponent();
        }

        private void check_Load(object sender, EventArgs e)
        {
            treeView1.ExpandAll();
        }

        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
         
            tree = e.Node.Text.ToString();
            tree1 = e.Node.Name.ToString();
            textBox1.Text = tree.ToString();

          

        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
        }
        public static int i=0;
        private void button3_Click(object sender, EventArgs e)
        {
            a = textBox1.Text ;
            b = textBox2.Text ;
            if (textBox2.Text != "")
            {
                    strSQL =strSQL + " and " + tree1.ToString() + "='" + textBox2.Text + "'";
                    textBox3.Text = a + "= " + b + "\r\n" + textBox3.Text;
                    strSQL1 = strSQL1 + " and " + tree1.ToString() + "='" + textBox2.Text + "'";
                    strSQL2 = strSQL2 + " and " + tree1.ToString() + "='" + textBox2.Text + "'";
            }
 
            textBox1.Text = "";
            textBox2.Text = "";
           
            //textBox3.Text = textBox3.Text + "ss = textBox1.Text,"

                                                          
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox3.Text = "";
            strSQL = "Select INHABITANTCODE_CHR AS 居民编号,RESIDENTNAME_CHR AS 居民姓名,COMMUNITYNAME_CHR AS 所属社区,COMMUNITYCODE_CHR AS 社区编号,FAMILYNAME_CHR AS 所属家庭,FAMILYCODE_CHR AS 家庭编号,PATIENTCARDID_CHR AS 诊疗卡号,SEX_CHR AS 性别,BIRTH_DAT AS 出生日期,COUNTRY_CHR AS 国籍,NATION_CHR AS 民族,PROVINCE_CHR AS 籍贯,IDENTITYCARD_CHR AS 身份证号,RESIDENTCARD_VCHR AS 居住证号,PHONE_CHR AS 本人电话,HOMEPHONE_VCHR AS 家庭电话,CONTACTPEOPLE_CHR AS 联系人姓名,CONTACTSTYLE_CHR AS 联系人电话,FATHERNAME_VCHR AS 父亲姓名,FATHERCODE_VCHR AS 父亲编号,MOTHERNAME_VCHR AS 母亲姓名,MOTHERCODE_VCHR AS 母亲编号,MARRIAGESTATE_CHR AS 婚姻状况,CAREERSTYLE_CHR AS 职业,COMPANY_CHR AS 工作单位,RESIDENTTYPE_VCHR AS 常住类型,CULTURE_VCHR AS 文化程度,REGISTADDRESS_VCHR AS 户口地址,ADDRESSPROVINCE_VCHR AS 家庭地址省,ADDRESSCITY_VCHR AS 家庭地址市,ADDRESSCOUNTY_VCHR AS 家庭地址县,ADDRESSVILLAGE_VCHR AS 家庭地址乡,ADDRESSHAMLET_VCHR AS 家庭地址村,ADDRESSDOORPLATE_VCHR AS 家庭地址号,POSTNUM_CHR AS 邮政编码,PAYTYPE_VCHR AS 医费支付方式,E_MAIL AS 邮箱地址,QQ AS QQ号码,MSN AS MSN号,CREATEDOCTOR_CHR AS 建档医生,CREATEDOCTORID_CHR AS 建档医生ID,CREATEUNIT_VCHR AS 建档单位,CREATEDATE_DAT AS 建档时间,RECORDER_CHR AS 录入者,RECORDERID_CHR AS 录入者ID,FAMILYCORD_CHR AS 家庭编号,FIXPHONE_VCHR AS 固定电话,HOMEADDRESS_VCHR AS 家庭地址,MEMBERCOUNT_INT AS 家庭人数,ENTIRONMENT_INT AS 居住环境,FAMILYTYPE_INT AS 家庭类型,FAMILYHOUSE_INT AS 家庭住房,HOUSEAREA_INT AS 住房面积,DRINKING_INT AS 饮水类型,EARNING_INT AS 家庭月收入,ELDING_INT AS 使用燃料,DISTANCE_INT AS 离最基层医疗机构距离,MOVEOUT_INT AS 是否迁出,MOVEOUTDATE_DAT AS 迁出日期,HOUSEHOLDERNAME_VCHR AS 户主名,CREATEORGAN_VCHR AS 建档机构,MEMBERCOUNT2_INT AS 家庭人口,ALLERGICREMEDY_VCHR AS 过敏药物,ALLERGICDATE_DAT AS 过敏时间,diseasename_vchr AS 疾病名称,happendate_dat AS 患病时间,diseasetype_int AS 疾病类型,diseaseIcd_vchr AS 疾病ICD码,healdate_dat AS 治愈时间,healeffect_vchr AS 治愈效果,diagnosehospital_vchr AS 确诊医院 from sqlview where 1=1 ";
            cn.Close();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            this.Visible = false;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            cn.Open();
            cm1 = new SqlDataAdapter(strSQL, cn);
            ds = new DataSet();
            cm1.Fill(ds, "sqlview");
            dataGridView1.DataSource = ds.Tables[0];
            comm1 = new SqlCommand(strSQL1,cn);
            dr1 = comm1.ExecuteReader();
            dr1.Read();
            label8.Text = dr1.GetValue(0).ToString();
            if (label8.Text == "")
                label8.Text = "0";
            dr1.Close();
            comm2 = new SqlCommand(strSQL2, cn);
            dr2 = comm2.ExecuteReader();
            dr2.Read();
            label6.Text = dr2.GetValue(0).ToString();
            if (label6.Text == "")
                label6.Text = "0";
            dr2.Close();
            int d=Convert.ToInt32(label8.Text)+ Convert.ToInt32(label6.Text);
            label4.Text = d.ToString();
            cn.Close();    
        }

    }
}
